package com.vision.sales.cm.data;

import java.util.Arrays;
import java.util.List;

/**
 * Contains the list of transaction types in the sales system.
 * 
 * WARNING: The names of the enum values are saved in the database. Changing the names
 * here can cause issues when matching the items into the ones saved in the database.
 * DO NOT MODIFY ANY OF THE ITEM NAMES.
 * 
 * @author Mark
 *
 */
public enum TransactionType {
	
	/**
	 * Not an actual transaction type, but serves like one in Customer Ledger report
	 */
	STARTING_BALANCE("Starting Balance"), 
	
	SALES_INVOICE("Sales"), // Debit
	
	DEBIT_MEMO_OVERRUNS("D/M Overruns"), // Debit
	DEBIT_MEMO_OVERPAYMENTS("D/M Overpayments"), // Debit
	
	ADVANCE_PAYMENT("Advance"), // Credit - NOTE: Used for AppliedAdvancePayment
	
	CREDIT_MEMO_DISCOUNTS("C/M Discounts"), // Credit
	CREDIT_MEMO_REJECTS("C/M Rejects"), // Credit
	CREDIT_MEMO_RETURNS("C/M Returns"), // Credit
	CREDIT_MEMO_BAD_DEBTS("C/M Bad Debts"), // Credit
	
	COLLECTION_PAYMENT("Collection"), // Credit
	COLLECTION_OVERPAYMENT("Overpayment"), // Debit
	COLLECTION_OVERRUNS("Overruns"), // Debit	
	COLLECTION_DISCOUNTS("Discounts"), // Credit
	COLLECTION_REJECTS("Rejects"), // Credit
	COLLECTION_RETURNS("Returns"), // Credit
	COLLECTION_TAX("W/Tax"), // Credit
	;
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	/**
	 * The list of {@link TransactionType}s considered as debit entries.
	 */
	public static final List<TransactionType> DEBIT_TYPES = Arrays.asList(
		new TransactionType[] {
			SALES_INVOICE,
			
			DEBIT_MEMO_OVERRUNS,
			DEBIT_MEMO_OVERPAYMENTS,
			
			COLLECTION_OVERPAYMENT,
			COLLECTION_OVERRUNS,
		}
	);
	
	/**
	 * The list of {@link TransactionType}s considered as credit entries.
	 */
	public static final List<TransactionType> CREDIT_TYPES = Arrays.asList(
		new TransactionType[] {
			ADVANCE_PAYMENT,
			
			CREDIT_MEMO_DISCOUNTS,
			CREDIT_MEMO_REJECTS,
			CREDIT_MEMO_RETURNS,
			CREDIT_MEMO_BAD_DEBTS,
			
			COLLECTION_PAYMENT,
			COLLECTION_DISCOUNTS,
			COLLECTION_REJECTS,
			COLLECTION_RETURNS,
			COLLECTION_TAX
		}
	);
		
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	private String displayText;
	
	private TransactionType(String displayText) {
		this.displayText = displayText;
	}
	
	public String getDisplayText() {
		return displayText;
	}
	
	public boolean isDebit() {
		return DEBIT_TYPES.contains(this);
	}
	
	public static boolean isDebit(TransactionType type) {
		return DEBIT_TYPES.contains(type);
	}
	
	public static boolean isCredit(TransactionType type) {
		return CREDIT_TYPES.contains(type);
	}

}
